package com.lianniu.mgr.product.service.impl;

import java.util.List;

import com.lianniu.mgr.product.model.ProductSpecVo;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.product.dao.IProductSpecValueDao;
import com.lianniu.mgr.product.model.ProductSpecValueVo;
import com.lianniu.mgr.product.service.IProductSpecValueService;
import com.lianniu.mgr.util.StringUtil;
@Service
public class ProductSpecValueServiceImpl implements IProductSpecValueService {
	
	private final static Logger logger = Logger.getLogger(ProductSpecValueServiceImpl.class);
	
	 @Autowired
	IProductSpecValueDao psvDao;

	@Override
	public BaseResult insertProductSpecValue(ProductSpecValueVo psvv) {
		logger.info("insertProductSpecValue begin");
	    logger.info("insertProductSpecValue: input data check begin");
	    logger.info("insertProductSpecValue psvv:" +JSON.toJSONString(psvv));

	    BaseResult baseResult;
	    if (StringUtil.isEmpty(psvv.getSpecValueName())) {
	      baseResult = BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }
	    logger.info("insertProductSpecValue: input data check end");
	    return BaseResult.success(psvDao.insertProductSpecValue(psvv));
	}

	@Override
	public BaseResult deleteById(String Id) {
		logger.info("deleteById begin");
		 logger.info("deleteById Id:" +Id);
		  
		 return BaseResult.success(psvDao.deleteById(Id));
	}

	

	@Override
	public BaseResult selectById(String specId) {
		logger.info("selectById begin");
		logger.info("selectById specId" +specId);
		List<ProductSpecValueVo> curPc=psvDao.selectById(specId);
		return BaseResult.success(curPc);
	}


	@Override
	public BaseResult insertProductSpecValues(List<ProductSpecValueVo> list) {
		// TODO Auto-generated method stub
		return BaseResult.success(psvDao.insertProductSpecValues(list));
	}

	@Override
	public BaseResult updateBySpecValueId(ProductSpecValueVo psvVo) {
		logger.info("updateBySpecValueId begin");
		logger.info("check data begin"+psvVo);
		return BaseResult.success(psvDao.updateBySpecValueId(psvVo));
	}

	@Override
	public BaseResult selectByLastId() {
		return BaseResult.success(psvDao.selecctByLastId());
	}


}
